package com.wgz.medicalmanagement.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wgz.medicalmanagement.common.entity.Result;
import com.wgz.medicalmanagement.domain.dto.MedicalRecordDTO;
import com.wgz.medicalmanagement.service.MedicalRecordService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;

/**
 * 就诊记录控制器
 */
@Slf4j
@RestController
@RequestMapping("/api/patients")
@Tag(name = "就诊记录接口", description = "提供患者就诊记录相关功能")
public class MedicalRecordController {
    
    @Autowired
    private MedicalRecordService medicalRecordService;
    
    /**
     * 获取患者就诊记录
     * 
     * @param id 患者ID
     * @param page 页码
     * @param size 每页大小
     * @return 就诊记录分页结果
     */
    @GetMapping("/{id}/medical-records")
    @Operation(summary = "获取患者就诊记录", description = "根据患者ID获取就诊记录，支持分页")
    @PreAuthorize("hasAnyAuthority('PATIENT_VIEW', 'ADMIN')")
    public Result<Page<MedicalRecordDTO>> getPatientMedicalRecords(
            @PathVariable Long id,
            @RequestParam(defaultValue = "0") Integer page,
            @RequestParam(defaultValue = "10") Integer size) {
        
        log.info("获取患者就诊记录, 患者ID: {}, 页码: {}, 每页大小: {}", id, page, size);
        
        Page<MedicalRecordDTO> records = medicalRecordService.getPatientMedicalRecords(id, page, size);
        
        return Result.success("获取就诊记录成功", records);
    }
} 